home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / ear / mui23dev.lha / MUI / Developer / Modula / Demo / ListDemo.mod < prev    next >
Text File  |  1994-06-04  |  10KB  |  293 lines

  1. MODULE ListDemo;
  2.  
  3. (* This little demo will show, how to write a MUI-Application using
  4. ** a list object and how to manage to set up the columns with a hook.
  5. **
  6. ** We will implement just a list and put some things into it.
  7. **
  8. ** Written 20.12.1993 by Christian 'Kochtopf' Scholz
  9. ** Email : ruebe@pool.informatik.rwth-aachen.de
  10. **   or, if pool does not work, try
  11. **   ruebe@tschil.informatik.rwth-aachen.de
  12. *)
  13.  
  14. (* 
  15. ** First some imports
  16. *)
  17.  
  18. (*$ StackChk:=FALSE *)
  19.  
  20. IMPORT  MD:MuiD;
  21. IMPORT  MM:MuiMacros;
  22. IMPORT  ExecD;
  23. FROM    MuiSupport  IMPORT APTR, DoMethod, DOMethod, fail;
  24. FROM    UtilityD    IMPORT HookPtr, Hook, tagEnd;
  25. FROM    ExecL       IMPORT Wait;
  26. FROM    Storage     IMPORT ALLOCATE, DEALLOCATE;
  27. FROM    SYSTEM      IMPORT TAG, ADR, LONGSET, ADDRESS, CAST;
  28. FROM    MuiMacros   IMPORT set, MakeHook, NoteClose, MakeID,
  29.                            (* These are for the list !! *)
  30.                            STRING, STRPTR, STRARR, STRARRPTR;
  31.  
  32. (*
  33. ** Types
  34. *)
  35.  
  36. TYPE    tagbuffer   = ARRAY[0..30] OF LONGINT;  (* for the taglists *)
  37.         (* Now the type for the list we want to have displayed *)
  38.         ListPtr     = POINTER TO ListContents;
  39.         (* we want 3 columns *)
  40.         ListContents  = RECORD
  41.                             Column1 : STRING;
  42.                             Column2 : STRING;
  43.                             Column3 : STRING;
  44.                         END;
  45.         EntryArr      = ARRAY[0..5] OF ListPtr;
  46.  
  47.  
  48.  
  49. (*
  50. ** Lets define some CONST for some Objects
  51. *)
  52.  
  53. CONST   True =1;
  54.         False=0;
  55.  
  56.         (* Lets define some entries for our little list.
  57.         ** normally you would do this by creating a new node of type ListContents
  58.         ** e.g. with ALLOCATE(newptr, SIZE(ListContents)) where newptr is defined
  59.         ** as ListPtr. Then you have to fill this new record and pass it to
  60.         ** MUIListInsert. But beware that you have to pass a pointer to a pointer.
  61.         ** So you have to write
  62.         ** DoMethod(list, TAG(buffer, MD.mmListInsert, ADR(newptr), 
  63.         **                              1, MD.mvListInsertBottom));
  64.         **
  65.         ** So remember to pass the type POINTER to ListPtr. ( or ADR(ListPtr) )
  66.         *)
  67.  
  68.  
  69.         e1   =ListContents{Column1 : "this",
  70.                          Column2 : "is the",
  71.                          Column3 : "first"};
  72.         e2   =ListContents{Column1 : "this",
  73.                          Column2 : "is the",
  74.                          Column3 : "second"};
  75.         e3   =ListContents{Column1 : "yeah!",
  76.                          Column2 : "the",
  77.                          Column3 : "third"};
  78.         e4   =ListContents{Column1 : "and this",
  79.                          Column2 : "is the",
  80.                          Column3 : "fourth"};
  81.         e5   =ListContents{Column1 : "last",
  82.                          Column2 : "but not",
  83.                          Column3 : "least"};
  84.  
  85.         (* This is an entry with 5 elements of ListPtr.
  86.         ** we have to give a pointer to this array to the ListInsert-Method.
  87.         *)
  88.         entries = EntryArr{ADR(e1),ADR(e2),ADR(e3),ADR(e4),ADR(e5),NIL};
  89.  
  90.  
  91. (*
  92. ** Now some Variables for some objects
  93. *)
  94.  
  95. VAR     app, window, list,
  96.         listview            : APTR;
  97.         msg                 : LONGINT;
  98.         signals             : LONGSET;
  99.         running             :=BOOLEAN{TRUE};
  100.         buffer, buffer1     : tagbuffer;
  101.         DspHook             : HookPtr;          (* this is for my display-hook *)
  102.  
  103. (* Lets define some lovely hook-functions *)
  104.  
  105.  
  106. PROCEDURE DspFunc(hook : HookPtr; array : APTR; listPtr : APTR) : APTR;
  107.     BEGIN
  108.     
  109.         (* if listPtr is NIL then we have to provide the titles *)
  110.         IF listPtr#NIL THEN (* normal entry *)
  111.         
  112.         (* Yeah! Wild casts ;-)
  113.         ** What we do here is to convert some strings to the format used
  114.         ** by C.
  115.         ** In C string-arrays are defined the following way :
  116.         **      array -> elem1 -> "string1"
  117.         **               elem2 -> "string2"
  118.         **                 .
  119.         **                 .
  120.         **                 .
  121.         ** So we have a pointer called 'array' which points to an array.
  122.         ** This array consists of pointers to strings.
  123.         ** Now we have to build that in M2.
  124.         ** The type of elem1 is STRPTR (a pointer to a string)
  125.         ** The type of array is STRARRPTR ( a pointer to a string array)
  126.         ** So look in MuiMacros.def where STRPTR, STRARR and STRARRPTR are defined.
  127.         ** So the array we get passed to our hook is an C-Array. So we have
  128.         ** to cast it to STRARRPTR, since it is one of these.
  129.         ** This is done by CAST(STRARRPTR, array).
  130.         ** Since this is a pointer we have to derefernce it with ^.
  131.         ** Then we have an array of type STRARR.
  132.         ** There we have to fill in the right pointers to our columns.
  133.         ** This is done by [0], [1] and [2].
  134.         ** The second CAST in a line casts the APTR which holds the pointer to
  135.         ** the element, we have to display to our real List-Type (here ListPtr).
  136.         ** Then we can dereference our ColumnX and fill in the address of it
  137.         ** in the array, which we get from MUI to fill in our strings.
  138.         ** Ofcourse we just fill in the pointer to the string (ADR).
  139.         ** (another way to do this is defining the ListContents-Type as follows :
  140.         ** TYPE ListContent = RECORD
  141.         **                      col1    : STRPTR;
  142.         **                      col2    : STRPTR;
  143.         **                      ...
  144.         ** The we do not need the ADR but must fill in directly the address of
  145.         ** the string.) Clear ?
  146.         ** (or just copy this code and modify it ;-)
  147.         *)
  148.  
  149.             CAST(STRARRPTR, array)^[0]:= ADR(CAST(ListPtr, listPtr)^.Column1);
  150.             CAST(STRARRPTR, array)^[1]:= ADR(CAST(ListPtr, listPtr)^.Column2);
  151.             CAST(STRARRPTR, array)^[2]:= ADR(CAST(ListPtr, listPtr)^.Column3);
  152.         
  153.         ELSE (* return titles ( centered, underlined ) *)
  154.             CAST(STRARRPTR, array)^[0]:= ADR("\033n\0333\033c\033uErste Spalte");
  155.             CAST(STRARRPTR, array)^[1]:= ADR("\033c\0333\033uZweite Spalte");
  156.             CAST(STRARRPTR, array)^[2]:= ADR("\033c\0333\033uDritte Spalte");
  157.         END;
  158.         RETURN 0; (* dummy return value *)
  159.     END DspFunc;
  160.  
  161.  
  162.  
  163. BEGIN
  164.     MakeHook(DspFunc, DspHook);             (* generate the hook *)
  165.  
  166.     (* lets create some objects *)
  167.  
  168.     list:=MM.ListObject(TAG(buffer,
  169.                 MD.maFrame,                 MD.mvFrameInputList,
  170.                 MD.maListDisplayHook,       DspHook,            (* here put the hook *)
  171.                 (* our format string *)
  172.                 MD.maListFormat,            ADR("P=\033c\033b D=8,P=\033c,P=\033c"),
  173.                 80423E66H,                  TRUE,               (* missing in 1.4 *)
  174.                 (*MD.maListTitle,             TRUE,               (* give it titles *)*)
  175.                tagEnd));
  176.     listview:=MM.ListviewObject(TAG(buffer,
  177.                 MD.maListviewList,          list,               (* put here our list *)
  178.                 tagEnd));
  179.  
  180.     (* now the window *)
  181.  
  182.     window:=MM.WindowObject(TAG(buffer,
  183.                 MD.maWindowTitle,       ADR("List-Demonstration"),
  184.                 MD.maWindowID,          MakeID("LDEM"),
  185.                 MM.WindowContents,
  186.                         MM.VGroup(TAG(buffer1,
  187.                             MD.maFrame,                 MD.mvFrameGroup,
  188.                             MD.maFrameTitle,            ADR("Do the list, err, twist"),
  189.                             MM.Child,                   listview,       (* just our list *)
  190.                             tagEnd)),
  191.                 tagEnd));
  192.  
  193.     app:=MM.ApplicationObject(TAG(buffer,
  194.                        MD.maApplicationTitle,      ADR("List-Demonstration"),
  195.                        MD.maApplicationAuthor,     ADR("Christian Scholz"),
  196.                        MD.maApplicationVersion,    ADR("$VER: ListDemo V0.1 (20.12.1993)"),
  197.                        MD.maApplicationCopyright,  ADR("© 1993 by Christian 'Kochtopf' Scholz"),
  198.                        MD.maApplicationDescription,ADR("Shows how to implement a list with MUI"),
  199.                        MD.maApplicationBase,       ADR("LD"),
  200.                        MM.SubWindow,               window,
  201.                        tagEnd));
  202.     IF app=NIL THEN fail(app,"failed to create app"); END;
  203.  
  204.     (* some notification *)
  205.  
  206.     NoteClose(app,window,MD.mvApplicationReturnIDQuit);
  207.     
  208.     (* set up the cycle chain *)
  209.  
  210.     DoMethod(window, TAG(buffer, MD.mmWindowSetCycleChain,
  211.                 listview, NIL, tagEnd));
  212.  
  213.  
  214.     (* set the active object *)
  215.  
  216.     set(window, MD.maWindowActiveObject, listview);
  217.  
  218.     (* open the window *)
  219.  
  220.     set(window, MD.maWindowOpen, True);
  221.  
  222.  
  223.     set(list, MD.maListQuiet, True);    (* that you don't see updating *)
  224.  
  225.     (* Insert something in the list
  226.     ** Here we call mmListInsert with an array of ListPtr, which shall be
  227.     ** inserted in our list. This array must be terminated with a NIL
  228.     ** and the count-value must be -1. (refer to autodocs)
  229.     *)
  230.  
  231.     DoMethod(list, TAG(buffer,
  232.             MD.mmListInsert, ADR(entries), -1, MD.mvListInsertBottom));
  233.  
  234.     (* and again! *)
  235.  
  236.     DoMethod(list, TAG(buffer,
  237.             MD.mmListInsert, ADR(entries), -1, MD.mvListInsertBottom));
  238.  
  239.  
  240.     set(list, MD.maListQuiet, False);   (* show the list *)
  241.  
  242.  
  243.     (* Main loop *)
  244.  
  245.     WHILE running DO
  246.         IF signals <> LONGSET{} THEN signals:=Wait(signals); END;
  247.  
  248.         (* get the message *)
  249.         msg:=DOMethod(app,TAG(buffer,
  250.                             MD.mmApplicationInput,ADR(signals)));
  251.  
  252.         CASE msg OF
  253.         | MD.mvApplicationReturnIDQuit :        (* not so much here ;-) *)
  254.                 running:=FALSE;
  255.         ELSE
  256.         END;
  257.     END; (* WHILE *)
  258.  
  259.     set(window,MD.maWindowOpen,False);          (* close window *)
  260.  
  261.     fail(app,"");                               (* say bye to the application *)
  262.  
  263. END ListDemo.
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.